//单例设计模式：在程序运行过程中，一个类只有一个实例
// class Person{
//     constructor(){
//         console.log(Person.instance)
//         if(!Person.instance){
//             console.log("第一次实例化")
//             Person.instance = this
//         }
//         return Person.instance
//     }
// }

// let p1 = new Person();

// let p2 = new Person();

// console.log(p1 === p2);


// class Person{
//     static getInstance(){
//         if(!Person.instance){
//             Person.instance = new Person();
//         }
//         return Person.instance
//     }
// }

// let p1 = Person.getInstance();

// let p2 = Person.getInstance();

// console.log(p1 === p2)

class Dialog{
    static getDialog(){
        if(!Dialog.instance){
            Dialog.instance = document.createElement('div');
            Dialog.instance.innerHTML = '内容';
            Dialog.instance.style.display = 'none';
            Dialog.instance.classList.add('dialog');
            document.body.appendChild(Dialog.instance);
        }
        return Dialog.instance
    }
}

let open = document.querySelector('#open');

let close = document.querySelector('#close');

open.addEventListener('click',() => {
    let dialog = Dialog.getDialog();

    dialog.style.display = 'block';
})


close.addEventListener('click',() => {
    let dialog = Dialog.getDialog();

    dialog.style.display = 'none';
})
